<?php
/* @var $this yii\web\View */
use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\HtmlPurifier;
use yii\bootstrap\Dropdown;
use yii\widgets\ListView;
use yii\bootstrap\ActiveForm;

$this->title =  '当前项目--'.$projectName;
$this->params['breadcrumbs'][] =$this->title;
?>
<?php include('_searchApi.php');?>


<div style="border:1px solid #ddd;" class="col-xs-9">
    <div style="background:#ffffff;padding:20px;">
        <h5 class="textshadow" >接口列表</h5>
    <?php $form = ActiveForm::begin([
        'id' => 'api-form',
        'method'=>"POST",
        'action'=>Url::to(['api/sort']),
        'options' => ['class' => 'form-horizontal'],
        'fieldConfig' => [
            'template' => "{label}\n<div class=\"col-xs-12\">{input}</div>\n<div class=\"col-xs-12\">{error}</div>",

        ],
    ]);
    ?>
   <input type="hidden" value="<?=$_GET['id']?>" name="id" />
            <table class="table">
                <thead>
                <tr>
                    <th class="col-md-2">接口编号</th>
                    <th class="col-md-9">接口名</th>
                    <th class="col-md-1">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($data as $key => $value) {?>
                    <tr>
                        <td><input name="api[]" type="hidden" value="<?=$value->apiId?>"><?=$value->number?></td>
                        <td><?=$value->apiName?></td>
                        <td>
                            <span onclick="up(this)" style="color:red;cursor: pointer" class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>
                            &nbsp;
                            <span  onclick="down(this)" style="color:green;cursor: pointer" class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>
                        </td>
                    </tr>
                <?php } ?>
                </tbody>
            </table>
            <button class="btn btn-success">提交</button>
    <?php ActiveForm::end(); ?>
    </div>
</div>

<script>
    //上移
    function up(obj){
        var $TR = $(obj).parents('tr');
        var prevTR = $TR.prev();
        prevTR.insertAfter($TR);
        $('tr.info').removeClass('info');
        $TR.addClass('info');
        $TR.hide();
        $TR.show(300);
    }
    //下移
    function down(obj){
        var $TR = $(obj).parents('tr');
        var nextTR = $TR.next();
        nextTR.insertBefore($TR);
        $('tr.info').removeClass('info');
        $TR.addClass('info');
        $TR.hide();
        $TR.show(300);
    }
</script>
